package com.javasm.springmybatis.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author：Dilraba
 * @Version：1.0
 * @Date：2021/11/9-14:50
 * @Since:jdk1.8
 * @Description:
 */
@Component
//1.SpringContainerUtils是用来获取spring容器中的对象
public class SpringContainerUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext=null;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext1) throws BeansException {
        applicationContext = applicationContext1;
    }

    public static <T> T getBean(Class<T> clazz){
        return applicationContext.getBean(clazz);
    }

}
